package com.bida.controller.admin;


import com.bida.domain.dto.*;
import com.bida.domain.po.Orders;
import com.bida.domain.vo.OrderPaymentVO;
import com.bida.domain.vo.OrderStatisticsVO;
import com.bida.domain.vo.OrderSubmitVO;
import com.bida.domain.vo.OrderVO;
import com.bida.result.PageResult;
import com.bida.result.Result;
import com.bida.service.IOrdersService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author ly
 * @since 2024-09-08
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrdersController {

    @Resource
    private IOrdersService orderService;

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> getOrdersPageConditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = orderService.getOrdersPageConditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getAllOrderStatistics(){
        OrderStatisticsVO orderStatisticsVO = orderService.getAllOrderStatistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrdersInfoById(@PathVariable("id") Long id){
        OrderVO orderVO = orderService.getOrdersInfoById(id);
        return Result.success(orderVO);
    }

    /**
     * 接单
     * @param orders
     * @return
     */
    @PutMapping("/confirm")
    public Result confirmOrdersById(@RequestBody Orders orders){
        orderService.confirmOrdersById(orders.getId());
        return Result.success();
    }

    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    public Result rejectionOrdersByIdReason(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception{
        orderService.rejectionOrdersByIdReason(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 取消订单
     * @param orderCancelDTO
     * @return
     * @throws Exception
     */
    @PutMapping("/cancel")
    public Result cancelOrderByIdReason(@RequestBody OrdersCancelDTO orderCancelDTO) throws Exception{
        orderService.cancelOrderByIdReason(orderCancelDTO);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result deliveryOrderById(@PathVariable("id") Long id){
        orderService.deliveryOrderById(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result completeOrderById(@PathVariable("id") Long id){
        orderService.completeOrderById(id);
        return Result.success();
    }



}
